define(function(){

    var pageTotal = {
            current: 1, //当前页
            count: 0,//总数据量
            pageCount: 2, //每页显示的数据量
            total: 0, //总共的页码
            first: 1, //首页
            last: 0, //尾页
            pre: 0, //上一页
            next: 0, //下一页
            getPages: function () { //计算分页信息
                pageTotal.total = Math.ceil(pageTotal.count / pageTotal.pageCount);
                pageTotal.last = pageTotal.total;
                pageTotal.pre = pageTotal.current - 1 <= 0 ? 1 : (pageTotal.current - 1);
                pageTotal.next = pageTotal.current + 1 >= pageTotal.total ? pageTotal.total : (pageTotal.current + 1);
            },
            //获取数据
            getDate: function (pageno, type) {
                console.log('message');
                if (pageno == null) {
                    pageno = 1;
                }
                //设置当前页
                pageTotal.current = pageno;
                // 记得导入你的数据
                pageTotal.count = 18;
                
                //获取分页样式
                pageTotal.page(type); //type表示分页栏样式
            },
            page: function (type) {

                //清除分页栏元素
                $("#pages").empty();
                //填充分页样式欠要加载分页数据
                pageTotal.getPages();
                if (type == 1) {

                    var x = 6;
                    //设置上下页
                    $("#pages").append("<span>" +pageTotal.current + "/" + pageTotal.total +"</span>" +"<a"+ " data-index=1"+">首页</a>");
                    var index = pageTotal.current <= Math.ceil(x / 2) ? 1 : (pageTotal.current) >= pageTotal.total - Math.ceil(x / 2) ? pageTotal.total - x : (pageTotal.current - Math.ceil(x / 2));
                    var end = pageTotal.current <= Math.ceil(x / 2) ? (x + 1) : (pageTotal.current + Math.ceil(x / 2)) >= pageTotal.total ? pageTotal.total : (pageTotal.current + Math.ceil(x / 2));
                    for (var i = index; i <= end; i++) {
                        if (i == pageTotal.current) {
                            $("#pages").append("<a class='on'"+" data-index="+i+">"+i +"</a>");
                        } else {
                            $("#pages").append("<a"+" data-index="+i+">"+i+"</a>");
                        }
                    }
                    if (end != pageTotal.total) {
                        $("#pages").append("<span>...</span>");
                    }
                    $("#pages").append("<a"+" data-index="+pageTotal.last+">尾页</a>");
                }
            }
    };

    return  pageTotal
})
